// axios 封装

import axios from 'axios'

export default async (ConfigArr,successCallBack = res => alert(res.msg),errorCallBack = msg => alert(msg) )=>{

    let type        = ConfigArr[0]!=='GET'?'data':'params',
        method      = ConfigArr[0],
        url         = ConfigArr[1],
        data        = ConfigArr[2]||{},
        
        CONFIG_DATA = { method,url,[type]:data },

        resData = await axios(CONFIG_DATA).catch(error => {
            if(error.response&&error.response.status === 404) return alert('接口不存在')
            if(error.response&&error.response.status === 500) return alert('服务端错误')
        });

    console.log(resData)
    const {code,msg} = resData.data;

    // 状态200 ok code为1
    if(code===1){
        successCallBack(resData.data)
        return 
    }
    // 状态200 ok code不唯一
    errorCallBack(msg)

        
}

